using System;
using System.Collections.Generic;
using System.Text;
using System.Xml;
using System.Data;
using System.Windows.Forms;
using System.Xml.Schema;
using System.IO;
using System.Drawing;
using OpenComposite.Base;
using OpenComposite.Repository.Properties;
using OpenComposite.EII.Designer.SCA;

namespace OpenComposite.EII.Repository
{
	[RepositoryItem(ItemType.System, "systems", "system_id")]
	public class RepositorySystem : RepositoryItemBaseEx
	{
		#region Initialization
		/// <summary>
		/// Initializes a new instance of the <see cref="RepositorySystem"/> class.
		/// </summary>
		public RepositorySystem()
			: base("system_id", "system_nm", "system_desc", "system_ntext", Resources.sNewSystem)
		{
			_symbol = null;
		}
		/// <summary>
		/// Initializes a new instance of the <see cref="RepositorySystem"/> class.
		/// </summary>
		/// <param name="bCreateNew">if set to <c>true</c> [b create new].</param>
		public RepositorySystem(bool bCreateNew)
			: this()
		{
			if ( bCreateNew )
				this.CreateNew();
		}
		/// <summary>
		/// Initializes a new instance of the <see cref="RepositorySystem"/> class.
		/// </summary>
		/// <param name="id">The id.</param>
		public RepositorySystem(int id)
			: this()
		{
			this.Load(id);
		}
		#endregion

		#region Properties

		/// <summary>
		/// Gets or sets the type.
		/// </summary>
		/// <value>The type.</value>
		public SystemType Type
		{
			get { return (SystemType)getValue("system_type", SystemType.SOBA); }
			set { setValue("Type", "system_type", value); }
		}

		/// <summary>
		/// Gets the type of the repository item.
		/// </summary>
		/// <value>The type of the repository item.</value>
		public override ItemType RepositoryItemType
		{
			get { return ItemType.System; }
		}
		/// <summary>
		/// Gets the name of the repository item type.
		/// </summary>
		/// <value>The name of the repository item type.</value>
		public override string RepositoryItemTypeName
		{
			get { return Resources.sSystem; }
		}
		/// <summary>
		/// Gets the repository item type description.
		/// </summary>
		/// <value>The repository item type description.</value>
		public override string RepositoryItemTypeDescription
		{
			get { return ""; }
		}

		/// <summary>
		/// Gets the image key.
		/// </summary>
		/// <value>The image key.</value>
		public override string ImageKey
		{
			get { return "system"; }
		}
		/// <summary>
		/// Gets the selected image key.
		/// </summary>
		/// <value>The selected image key.</value>
		public override string SelectedImageKey
		{
			get { return this.ImageKey; }
		}
		/// <summary>
		/// Gets the image.
		/// </summary>
		/// <value>The image.</value>
		public override Image Image
		{
			get { return Resources.ico_system.ToBitmap(); }
		}
		/// <summary>
		/// Gets the selected image.
		/// </summary>
		/// <value>The selected image.</value>
		public override Image SelectedImage
		{
			get { return this.Image; }
		}

		/// <summary>
		/// Gets the name of the table.
		/// </summary>
		/// <value>The name of the table.</value>
		public override string TableName
		{
			get { return "systems"; }
		}
		private static List<ItemType> _LISTALLOWED =
			new List<ItemType>(new ItemType[] { ItemType.GenericFolder, ItemType.System, ItemType.Composite });
		/// <summary>
		/// Gets the allowed child types.
		/// </summary>
		/// <value>The allowed child types.</value>
		public override List<ItemType> AllowedChildTypes
		{
			get { return _LISTALLOWED; }
		}

		private ServiceComponentSymbol _symbol;
		/// <summary>
		/// Gets or sets the symbol.
		/// </summary>
		/// <value>The symbol.</value>
		public ServiceComponentSymbol Symbol
		{
			get { return _symbol; }
			set { _symbol = value; }
		}

		#endregion

		#region Methods

		/// <summary>
		/// Gets the icon.
		/// </summary>
		/// <returns></returns>
		public override Icon GetIcon()
		{
			return Resources.ico_system;
		}
		/// <summary>
		/// Copies this instance.
		/// </summary>
		/// <param name="deep"><c>true</c> to recursively copy the item and all subitems;
		/// <c>false</c> to copy only the item itself.</param>
		/// <returns>The copied item.</returns>
		public override IRepositoryItem Copy(bool deep)
		{
			RepositorySystem copy = new RepositorySystem(true);
			copy.InitializeServiceProvider(this);
			this.CopyDataRowToTarget(copy);
			return copy;
		}

		#endregion Methods

		#region Enum: SystemType
		public enum SystemType
		{
			SOBA = 0,
			Subsystem
		}
		#endregion
	}
}